<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Mua~亲亲宠————${user.loginname}的钱包</title>
<link rel="stylesheet" href="css/style.css" />

<link rel="stylesheet" href="css/bootstrap.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>

<body>
	<%@ include file="/WEB-INF/jsp/mgnt/mgntTop.jspf"%>
	<div class="container  col-sm-offset-2  col-sm-8">
		<div class="page-header" style="color:#000099">
			<h3>${user.loginname}的钱包</h3>
		</div>
		余额：${account.balance}元
		<div class="row">
			<input type="hidden" id="userId" value="${user.id}" />
			<div class="form-group form-inline">
				<label class="col-sm-4 control-label"> 充值：</label>
				<div class="col-sm-6">
					<span><input type="text" id="toAdd" size='8'>&nbsp;&nbsp;元</span>
				</div>
			</div>
			<div class="form-group form-inline">
				<button class="btn btn-success col-sm-2"
					onclick="updateAccount($('#toAdd').val(), true)">充值</button>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-4 control-label"> 提现：</label>
				<div class="col-sm-6">
					<span><input type="text" id="toGet" size='8'>&nbsp;&nbsp;元</span>
				</div>
			</div>
			<div class="form-group form-inline">
				<button class="btn btn-success  col-sm-2"
					onclick="updateAccount($('#toGet').val(), false)">提现</button>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		function updateAccount(money, isAdd) {
			var reg = /^[0-9]+(\.\d{1,2})?$/;
			if (!reg.test(money)) {
				$(".modal-body").html("请输入正确金额！");
				$("#topModal").modal("show");
				return;
			}
			$.ajax({
				url : "manage/updateUserAccount.do",
				data : {
					"userId" : $('#userId').val(),
					"money" : money,
					"isAdd" : isAdd
				},
				type : "POST",
				success : function(result) {
					//请求成功时
					if (result.msg == 'success') {
						$(".modal-body").html("成功！");
						$("#topModal").modal("show");
						$("#topModal").on(
								'hidden.bs.modal',
								function() {
									var gotoURL = "manage/updateAccount.do?id="
											+ $('#userId').val();
									window.location.href = gotoURL;
								});
					} else if (result.msg == 'error') {
						$(".modal-body").html(result.errorMsg);
						$("#topModal").modal("show");
					}
				},
				error : function() {
					//请求失败时
					$(".modal-body").html("失败");
					$("#topModal").modal("show");
				}
			});
		}
	</script>
</body>
</html>
